package com.charity.service.serviceImpl;

import com.charity.mapper.AdminMapper;
import com.charity.model.CommonResponse;
import com.charity.pojo.Admin;
import com.charity.pojo.Donation;
import com.charity.pojo.Entry;
import com.charity.pojo.User;
import com.charity.service.AdminService;
import com.charity.service.CharityService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.fisco.bcos.sdk.transaction.model.dto.CallResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    public static final String PubKey = com.charity.utils.IOUtil.readResourceAsString("conf/PubKey");
    public static final String PriKey = com.charity.utils.IOUtil.readResourceAsString("conf/PriKey");

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private CharityService charityService;

    private CommonResponse commonResponse = new CommonResponse();

    @Override
    public Admin admin(String userName, String password) {
        return adminMapper.admin(userName, password);
    }

    @Override
    public Integer addAdmin(String userName, String password, String realName, String phone, String email, String createDate) {
        return adminMapper.addAdmin(userName, password, realName, phone, email, createDate);
    }

    @Override
    public Long adminId(String userName) {
        return adminMapper.adminId(userName);
    }

    @Override
    public Admin adminById(Long id) {
        return adminMapper.adminById(id);
    }

    @Override
    public Integer updateAdmin(Long id, String userName, String password, String realName, String phone, String email) {
        return adminMapper.updateAdmin(id, userName, password, realName, phone, email);
    }

    @Override
    public Integer deleteAdmin(Long id) {
        return adminMapper.deleteAdmin(id);
    }

    @Override
    public List<User> users() {
        return adminMapper.users();
    }

    @Override
    public List<Admin> admins() {
        return adminMapper.admins();
    }

    @Override
    public List<Donation> donations() throws Exception {
        List<Donation> donations = adminMapper.donations();
        CallResponse callResponse = charityService.searchAllDonation();
        if (donations != null && callResponse.getValues() != null) {
            return donations;
        }
        return null;
    }

    @Override
    public List<Entry> entrys() throws Exception {
        List<Entry> entrys = adminMapper.entrys();
        return entrys;
    }

}
